<template>
  <div id="home">
    <van-button class="sharebutton" type="info" @click="junpShare()"></van-button>
    <van-form @submit="junpSubmit" class="noBorder">
      <van-button type="info" block native-type="submit"></van-button>
    </van-form>
  </div>
</template>

<script>
  import { Form, Button } from 'vant'
  export default {
    name: 'ZryHome',
    data() {
      return {
        spreadUserId: '',
        jumpFlag: false
      }
    },
    components: {
      'van-form': Form,
      'van-button': Button
    },
    activated () {
      this.getIP()
    },
    methods: {
      getIP () {
        var queryArray = this.getQueryString()
        this.spreadUserId = queryArray['spreadUserId']
        if (this.spreadUserId) {
          this.jumpFlag = true
          localStorage.setItem('spreadUserId', this.spreadUserId)
          var parm = {
            eventId: "2",
            ip: localStorage.getItem('Ip'),
            address: localStorage.getItem('cityname'),
            browser: localStorage.getItem('browser'),
            spreadUserId: this.spreadUserId
          }
          var url = this.HOME + 'api/h5/EqxiuVisit/visit';
          this.$axios({
            method: 'post',
            url: url,
            data: {entity:parm}
          }).then((res) => {
            if (res.data.code === 200) {
              this.jumpFlag = true
            }
          }).catch((err) => {
            this.jumpFlag = true
            this.$toast.fail('网络异常')
          }) 
        } else {
          this.jumpFlag = false
        }
      },
      junpSubmit() {
        if (this.jumpFlag) {
          this.$router.push({ path: '/zry/ZryFillIn' }) 
        } else {
          this.$toast.fail('非常抱歉，我们检测不到推广人员信息')
        }
      },
      junpShare() {
        if (this.jumpFlag) {
          this.$router.push({ path: '/zry/ZryShare' }) 
        } else {
          this.$toast.fail('非常抱歉，我们检测不到推广人员信息')
        }
      },
      getQueryString() {
        const url = location.href; //获取url中"?"符后的字串
        let theRequest = new Object()
        if (url.indexOf("?") != -1) {
            let str = url.split('?')
            str = str[1].split("&")
            for(let i = 0; i < str.length; i ++) {
              theRequest[str[i].split("=")[0]]=unescape(str[i].split("=")[1])
            }
        }
        return theRequest;
      }
    }
  }
</script>

<style scoped>
  #home {
    background: url('../../assets/images/zry/b1.png') no-repeat 100% 0;
    background-size: 100%;
  }
  .sharebutton {
    width: 2em;
    height: 2em;
    margin-top: 0.2rem;
    margin-left: 3.3rem;
    background: url('../../assets/images/zry/zhuanfa.png') no-repeat 100% 100%;
    background-size: 100%;
    border: none;
  }
  button {
    width: 98%;
    margin: 0 auto;
    margin-top: 5.71rem;
    background: url('../../assets/images/zry/btn-1.png') no-repeat 50% 50%;
    background-size: 100%;
    border: none;
  }
</style>
